package com.example.demo.repository;

import com.example.demo.entity.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * Copyright (C), 2019-2019, XXX有限公司
 * FileName: ProductRepository
 * Author:   longzhonghua
 * Date:     2019/4/12 19:51
 *
 * @Description: $description$
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
public interface ProductRepository extends JpaRepository<Product, Long> {
    Product findByid(long id);
    @Query(value = "update Product p set p.available_count=p.available_count-:count where p.id=:id and p.available_count>=:count")
    @Modifying
    int updateStock(@Param("id") Long product_id,@Param("count") Integer count);
}
